package com.psm.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
/**
 * 
 * @author 广州朴石茗文化发展有限公司
 * @Email pushiming@sina.cn
 */
public class PuTerm extends Model<PuTerm>{
	
	public static String tableName="pu_terms";

    public static final PuTerm me = new PuTerm();
    /**
     * 获取类型列表
     * @param pageNumber 页码
     * @param pageSize 显示数
     * @param where 条件
     * @param param 参数
     * @return
     */
    public DataGrid getTerms(int pageNumber, int pageSize,StringBuffer where,List<Object> param){
    	
    	DataGrid dg = new DataGrid();
    	Page<Record> p = Db.paginate(pageNumber, pageSize, "select p.*,t.name as pname,c.name as sname ", "from "+this.tableName+" p left join pu_terms t on p.parent = t.term_id left join sys_pa_code c on p.status = c.id " + where.toString(), param.toArray());

        dg.setRows(p.getList());
        dg.setTotal(p.getTotalRow());
        
        return dg;
    }
    /**
     * 获取类型,用于下拉数据列表
     * @return
     */
    public List<Record> getTermsToSelect(){
    	List<Record> list= Db.find("select a.term_id,a.name from pu_terms a");
        return list;
    }
    /**
     * 获取指定类型子项
     * @param penter 父节点id
     */
    public List<Record> getTermsForPenter(String penter){
    	
    	List<Record> list= Db.find("select a.*,b.name pname from pu_terms a left join "+this.tableName+" b on a.parent = b.term_id where a.parent = ? order by listorder", new Object[]{penter});
        return list;
    }

}
